exports.craetePrizeUser = async (cloud, params, mixNick) => {
    try{
        let create_sql = 'insert into el_user_prize (mixnick, user_id, nick, award_type, prize_name, win_date, name, phone, nick_id, address) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
        let create_info = await cloud.dataspace.executeSql(create_sql, [mixNick, params.user_id, params.nick, params.award_type, params.prize_name, params.win_date, '', '', '', '']);
    
        return {
            status: "success",
            info: create_info
        }
    }catch(err){
        return {
            status: "fail",
            info: err
        }
    }
}

exports.findPrizeUserInfo = async (cloud, mixNick, params) => {
    try{
        let select_sql = 'select * from el_user_prize where user_id = ? and mixnick = ?';
        let select_info = await cloud.dataspace.executeSql(select_sql, [params.user_id, mixNick]);

        return {
            status: "success",
            info: select_info
        }
    }catch(err){
        return {
            status: "fail",
            info: err
        }
    }
}

exports.findPrizeUserCount = async (cloud, mixNick, params) => {
    try{
        let select_sql = 'select count(*) as count from el_user_prize where user_id = ? and mixnick = ?';
        let select_info = await cloud.dataspace.executeSql(select_sql, [params.user_id, mixNick]);

        return {
            status: "success",
            info: select_info
        }
    }catch(err){
        return {
            status: "fail",
            info: err
        }
    }
}

exports.findAllUerInfo = async (cloud) => {
    try{
        let select_sql = 'select * from el_user_prize order by win_date desc limit 100';
        let select_info = await cloud.dataspace.executeSql(select_sql, []);

        return {
            status: "success",
            info: select_info
        }
    }catch(err){
        return {
            status: "fail",
            info: err
        }
    }
}

exports.updatePrizeInfo = async (cloud, params, mixNick) => {
    try{
        let update_sql = 'update el_user_prize set name = ?, phone = ?, nick_id = ?, address = ? where user_id = ? and mixnick = ? and award_type = ?';
        let update_info = await cloud.dataspace.executeSql(update_sql, [params.name, params.phone, params.nick_id, params.address, params.user_id, mixNick, params.award_type]);
        
        return {
            status: "success",
            info: update_info
        }
    }catch(err){
        return {
            status: "fail",
            info: err
        }
    }
}
